/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.Tadama.rms;

import com.Tadama.Bean.beCliente;
import javax.microedition.rms.*;
import java.io.*;
import java.util.Vector;

/**
 *
 * @author LP
 */
public class rmsCliente {
    private String NombreRMS = "rmsCliente";
    private RecordStore rs = null;

    public rmsCliente() {}

    private void AbrirRMS(){
        try{
            rs = RecordStore.openRecordStore(NombreRMS, true);
        }catch (RecordStoreException rse){
            System.out.println("Error!!");
        }
    }
    
    private void CerrarRMS(){
        try{
            rs.closeRecordStore();
        } catch (RecordStoreException rse){
            System.out.println("Error!!");
        }
    }
    
    public void agregarRecord(beCliente cliente)
	{
		AbrirRMS();
                byte[] outputRecord;
                try {
                    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                    DataOutputStream outputDataStream = new DataOutputStream(outputStream);

                    outputDataStream.writeUTF(cliente.getPersonaRazonSocial());

                    outputDataStream.flush();
                    outputRecord = outputStream.toByteArray();
                    rs.addRecord(outputRecord, 0, outputRecord.length);
                    outputStream.reset();
                    outputStream.close();
                    outputDataStream.close();
                } catch (Exception error) {
                    error.printStackTrace();
                }
                CerrarRMS();
	}
}
